<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Expires", "0");
    %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>网络服务平台</title>
    <link rel="stylesheet" type="text/css" href="/js/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/js/easyui/themes/icon.css">
    <script type="text/javascript" src="/js/easyui/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="/js/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#newsSourceGrid').datagrid({
                title:'新闻采集源列表',
                iconCls:'icon-save',
                height:460,
                nowrap:false,
                striped:true,
                collapsible:true,
                url:'/management/news/fetchNewsSource.action',
                queryParams:{"inIndex":"-1", "indexLevel":"-1"},
                remoteSort:false,
                idField:'id',
                frozenColumns:[
                    [
                        {"width":280, "field":"source", "title":"来源"},
                        {"width":320, "field":"startUrl", "title":"抓取URL"},
                        {"width":120, "field":"lastUpdate", "title":"最近更新"},
                        {"width":100, "field":"imageFolder", "title":"图片目录"},
                        {"width":100, "field":"id", "title":"操作",
                            formatter:function (value, rowData, rowIndex) {
                                <s:if test="1 == #session._user_role_">
                                return '<a href="newsSourceForm.action?id=' + value + ' ">编辑</a>&nbsp;<a onclick="deleteNewsSource(\'' + value + '\',\'' + rowIndex + '\');" href="#">删除</a>' +
                                        '&nbsp;<a onclick="testNewsSource(\'' + value + '\');" href="#">测试</a>';
                                </s:if>
                                <s:else>
                                return '<a href="newsSourceForm.action?id=' + value + ' ">编辑</a>' +
                                        '&nbsp;<a onclick="testNewsSource(\'' + value + '\');" href="#">测试</a>';
                                </s:else>
                            }
                        }
                    ]
                ],
                columns:[
                    [
                        {"width":280, "field":"listSelector", "title":"列表"}
                        /* {"width":80, "field":"listNext", "title":"列表下一页"},
                        {"width":100, "field":"listBasePath", "title":"列表下一页Base"},
                        {"width":80, "field":"title", "title":"标题"},
                        {"width":80, "field":"introduction", "title":"摘要"},
                        {"width":80, "field":"date", "title":"日期"},
                        {"width":80, "field":"dateFormat", "title":"日期格式"},
                        {"width":80, "field":"author", "title":"作者"},
                        {"width":80, "field":"context", "title":"正文"},
                        {"width":80, "field":"next", "title":"文章下一页"},
                        {"width":100, "field":"nextBasePath", "title":"文章下一页Base"},
                        {"width":100, "field":"imageBasePath", "title":"图片Base"}*/
                    ]
                ],
                pagination:true,
                rownumbers:true,
                toolbar:[
                    {"iconCls":"icon-add", "handler":function () {
                        openAddSource();
                    }, "text":"添加新闻源", "title":"添加新闻源", "id":"btnAdd"}
                ]
            });

            $('#indexLevel').combobox('setValue', -1);
            $('#inIndex').combobox('setValue', -1);

            var p = $('#newsSourceGrid').datagrid('getPager');
            if (p) {
                $(p).pagination({
                    onBeforeRefresh:function () {
                        //	alert('before refresh');
                    }
                });
            }
        });

        function openAddSource() {
            window.location.href = "newsSourceForm.action";
        }

        function showNews() {
            var rows = $('#newsSourceGrid').datagrid('getSelections');
            var row = $('#newsSourceGrid').datagrid('getSelected');
            if (rows.length == 1) {
                window.open("/management/news/showNews.action?id=" + row.id);
            } else if (rows.length < 1) {
                $.messager.alert('警告', '请选择一条记录!', 'warning');
            }
            else {
                $.messager.alert('警告', '一次只能查看一条记录!', 'warning');
            }
        }

        function openAboutNews() {
            var rows = $('#newsSourceGrid').datagrid('getSelections');
            var row = $('#newsSourceGrid').datagrid('getSelected');
            if (rows.length == 1) {
                window.location = "aboutNews.action?id=" + row.id;
            } else if (rows.length < 1) {
                $.messager.alert('警告', '请选择一条记录!', 'warning');
            }
            else {
                $.messager.alert('警告', '一次只能选择一条记录!', 'warning');
            }
        }

        function openUpdateNews() {
            var rows = $('#newsSourceGrid').datagrid('getSelections');
            var row = $('#newsSourceGrid').datagrid('getSelected');
            if (rows.length == 1) {
                window.location = "newsForm.action?id=" + row.id;
            } else if (rows.length < 1) {
                $.messager.alert('警告', '请选择一条记录!', 'warning');
            }
            else {
                $.messager.alert('警告', '一次只能修改一条记录!', 'warning');
            }
        }

        function testNewsSource(id) {
            $.messager.progress({
                title:'提示信息',
                msg:'测试新闻源......！'
            });

            $.getJSON("/management/news/testNewsSource.action?id=" + id, function (data1) {
                if (data1.successful) {
                    $.messager.progress("close");
                    $.messager.show({
                        title:'提示信息',
                        timeout:5000,
                        msg:data1.serverMessage
                    });
                }
            });
        }

        function deleteNewsSource(id, index) {
            $.messager.confirm('删除新闻源', '你确定要删除新闻源吗？', function (data) {
                if (!data) {
                    return;
                }

                $.getJSON("/management/news/deleteNewsSource.action?id=" + id, function (data1) {
                    if (data1.successful) {
                        $.messager.show({
                            title:'提示信息',
                            msg:'删除新闻源成功！'
                        });

                        var index = $("#newsSourceGrid").datagrid('getRowIndex', id);
                        $('#newsSourceGrid').datagrid('deleteRow', index);
                    } else {
                        $.messager.show({
                            title:'提示信息',
                            msg:'删除新闻源失败！'
                        });
                    }
                });
            });
        }

        function query() {
            var newsSourceTitle = $("#newsSourceTitle").val();
            var queryParams = $('#newsSourceGrid').datagrid('options').queryParams;

            queryParams.newsSourceTitle = newsSourceTitle;

            $('#newsSourceGrid').datagrid('options').queryParams = queryParams;
            $("#newsSourceGrid").datagrid('reload');
        }

        function getSelected() {
            var selected = $("#newsSourceGrid").datagrid("getSelected");
            return selected;
        }

        function getSelections() {
            var rows = $("#newsSourceGrid").datagrid("getSelections");
            return rows;
        }

        function selectRow(rowNumber) {
            $("#newsSourceGrid").datagrid("selectRow", rowNumber);
        }

    </script>

</head>

<body class="easyui-layout">
<s:if test="null == #session._login_user_">
    <script type="text/javascript">
        top.location.href = '/admin';
    </script>
</s:if>
<div region="center" style="height:600px;padding:10px;background:#efefef;">
    <div id="p" class="easyui-panel" title="新闻搜索" icon="icon-search" style="height:80px;padding:10px;">
        <table style="border: #15428B; border-style: solid; border-width: 1px ">
            <tr>
                <td><label>来源:</label></td>
                <td>&nbsp;<input name="newsSourceTitle" id="newsSourceTitle"/></td>
                <td><a class="easyui-linkbutton" onclick="query()">搜索</a></td>
            </tr>
        </table>
    </div>
    <div id="p1" class="easyui-panel" style="height:500px;">`
        <table id="newsSourceGrid"></table>
    </div>
</div>
</body>
</html>